#include "entitypreview.h"
#include "gfxitems/gfxUnit.h"
#include "gfxitems/gfxTowerBeam.h"
#include <math.h>
#include <QDebug>

EntityPreview::EntityPreview(QWidget *parent) :
   QFrame(parent)
{
   mStats.type = ENTITY_UNIT;
   mStats.kind = 8;
   mStats.size = 1;
   mStats.color = QColor(Qt::red).rgb();
}


void EntityPreview::paintEvent(QPaintEvent *event)
{
   QWidget::paintEvent(event);

   QPainter painter(this);
   painter.translate(width()/2, height()/2);

   if (mStats.type == ENTITY_UNIT)
   {
      GFXUnit::doPaint(mStats.color, mStats.size, mStats.kind, 1, painter, 2.0);
   }
   else if (mStats.type == ENTITY_TOWER)
   {
      switch (mStats.kind)
      {
      case TOWER_BEAM:
         GFXTowerBeam::doPaint(mStats.color, mStats.size, false, false, painter, 2.0);
      break;
      default: break;
      }
   }
   else // ENTITY_NONE
   {

   }
}

void EntityPreview::clearEntity() { mStats.type = ENTITY_NONE; }
void EntityPreview::setEntityType(const ENTITY_TYPE value) { mStats.type = value; update(); }
void EntityPreview::setEntityKind(const int value) { mStats.kind = value; update(); }
void EntityPreview::setEntitySize(const int value) { mStats.size = value; update(); }
void EntityPreview::setEntityColor(const QColor &value) { mStats.color = value.rgb(); update(); }
void EntityPreview::setEntityStats(const EntityBaseStats &stats) { mStats = stats; update(); }
ENTITY_TYPE EntityPreview::entityType() { return mStats.type; }
qint32 EntityPreview::entityKind() { return mStats.kind; }
qint32 EntityPreview::entitySize() { return mStats.size; }
QColor EntityPreview::entityColor() { return mStats.color; }
EntityBaseStats EntityPreview::entityStats() { return mStats; }
